package com.anstudio;

import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.http.util.EncodingUtils;

public class AnStudioUtil {

    public static boolean asIsInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
            } catch (NumberFormatException e) {
                return false;
            }
    }

    public static void asWriteString2File(String fileName, String content, boolean isConcat) {

      try{
        FileWriter writer = new FileWriter(fileName,isConcat);
        writer.write(content);
        writer.close();
            }
      catch(IOException e){
        e.printStackTrace();
        }
    }

    public static String asReadFile2String(String fileName) {
      String res = "";
        try {
          FileInputStream fin = new FileInputStream(fileName);
          int length = fin.available();
          byte [] buffer = new byte[length];
          fin.read(buffer);
          res = EncodingUtils.getString(buffer, "utf-8");
          fin.close();
          }
        catch(Exception e) {
          e.printStackTrace();
          }
        return res;
    }

}
